using System;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using UwinEducation.Domain.Entities;
using UwinEducation.Shared.Converters;
using UwinEducation.Shared.Enums;

namespace UwinEducation.Application.Dtos
{
    /// <summary>
    /// 教师课表DTO
    /// </summary>
    public class TeacherScheduleDto
    {
        /// <summary>
        /// 课表ID
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 教师ID
        /// </summary>
        public Guid TeacherId { get; set; }

        /// <summary>
        /// 教师姓名
        /// </summary>
        public string TeacherName { get; set; }

        /// <summary>
        /// 课程ID
        /// </summary>
        public Guid CourseId { get; set; }

        /// <summary>
        /// 课程名称
        /// </summary>
        public string CourseName { get; set; }

        /// <summary>
        /// 课程颜色
        /// </summary>
        public string CalenderColor { get; set; }
        /// <summary>
        /// 教室ID
        /// </summary>
        public Guid? ClassroomId { get; set; }

        /// <summary>
        /// 教室名称
        /// </summary>
        public string ClassroomName { get; set; }

        /// <summary>
        /// 教室容量
        /// </summary>
        public int ClassroomCapacity { get; set; }

        /// <summary>
        /// 已报名人数
        /// </summary>
        public int EnrolledCount { get; set; }

        /// <summary>
        /// 单价(元/课时)
        /// </summary>
        public decimal UnitPrice { get; set; }

        /// <summary>
        /// 人数限制
        /// </summary>
        public int Capacity { get; set; }
        /// <summary>
        /// 课程数量
        /// </summary>
        public int CourseCount { get; set; }

        /// <summary>
        /// 上课时间
        /// </summary>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 下课时间
        /// </summary>
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 课表状态
        /// </summary>
        public ScheduleStatus Status { get; set; }

        /// <summary>
        /// 废弃原因
        /// </summary>
        public string? Reason { get; set; }

        /// <summary>
        /// 组ID
        /// </summary>
        public Guid GroupId { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 老师上课方式类型
        /// </summary>
        public CourseType CourseType { get; set; }

        /// <summary>
        /// 老师课程详情
        /// </summary>
        public List<TeacherScheduleDetailsDto> TeacherScheduleDetails { get; set; }
        /// <summary>
        /// 学生集合
        /// </summary>
        public List<StudentDto> Students { get; set; }

    }

    /// <summary>
    /// 教师课表统计DTO
    /// </summary>
    public class TeacherScheduleDetailsDto
    {
        /// <summary>
        /// 教师课程详情ID
        /// </summary>
        public Guid Id { get; set; }
        /// <summary>
        /// 课程状态
        /// </summary>
        public ScheduleStatus Status { get; set; }
        /// <summary>
        /// 废弃原因
        /// </summary>
        public string Reason { get; set; }

        /// <summary>
        /// 上课时间
        /// </summary>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 下课时间
        /// </summary>
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 学生上课类型
        /// </summary>
        public CourseType CourseType { get; set; }

        public string Remarks { get; set; }

        public Guid? OrderDetailId { get; set; }

        /// <summary>
        /// 教师课表
        /// </summary>
        public TeacherScheduleDto TeacherSchedule { get; set; }
        /// <summary>
        /// 学生集合
        /// </summary>
        public List<StudentDto> Students { get; set; }
    }

    /// <summary>
    /// 创建教师课表时间规则DTO
    /// </summary>
    public class CreateTeacherScheduleRulesDto
    {
        /// <summary>
        /// 星期几 (1-7, 1代表星期一)
        /// </summary>
        [Required(ErrorMessage = "星期几不能为空")]
        [Range(0, 6, ErrorMessage = "星期几必须在0-6之间")]
        public int DayOfWeek { get; set; }

        /// <summary>
        /// 开始时间 (HH:mm)
        /// </summary>
        [Required(ErrorMessage = "开始时间不能为空")]
        public TimeSpan StartTime { get; set; }

        /// <summary>
        /// 结束时间 (HH:mm)
        /// </summary>
        [Required(ErrorMessage = "结束时间不能为空")]
        public TimeSpan EndTime { get; set; }
        /// <summary>
        /// 课程类型
        /// </summary>
        [Required(ErrorMessage = "课程类型(线上/线下)不能为空")]

        public CourseType CourseType { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }
    }

    public class BatchCreateTeacherScheduleDto
    {
        /// <summary>
        /// 教师ID
        /// </summary>
        [Required(ErrorMessage = "教师ID不能为空")]
        public Guid TeacherId { get; set; }

        /// <summary>
        /// 课程ID
        /// </summary>
        [Required(ErrorMessage = "课程ID不能为空")]
        public Guid CourseId { get; set; }

        /// <summary>
        /// 教室ID
        /// </summary>
        public Guid? ClassroomId { get; set; }

        /// <summary>
        /// 单价(元/课时)
        /// </summary>
        [Required(ErrorMessage = "单价不能为空")]
        public decimal UnitPrice { get; set; }

        /// <summary>
        /// 人数限制
        /// </summary>
        [Required(ErrorMessage = "人数限制不能为空")]
        public int Capacity { get; set; }

        /// <summary>
        /// 开课日期
        /// </summary>
        [Required(ErrorMessage = "开课日期不能为空")]
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 结课日期
        /// </summary>
        [Required(ErrorMessage = "结课日期不能为空")]
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 是否强制校验
        /// </summary>
        public bool IsForceCheck { get; set; } = true;

        /// <summary>
        /// 学生课表添加是否强制校验
        /// </summary>
        public bool IsStudentScheduleCheck { get; set; } = true;

        /// <summary>
        /// 创建教师课表时间规则DTO
        /// </summary>
        [Required(ErrorMessage = "时间规则不能为空")]
        public List<CreateTeacherScheduleRulesDto> CreateTeacherScheduleRulesDtos { get; set; }

        /// <summary>
        /// 学生IDs
        /// </summary>
        public List<CreateScheduleDto>? StudentIds { get; set; }

        /// <summary>
        /// 预约IDS
        /// </summary>
        public List<Guid>? AppointmentIds { get; set; }
        

        /// <summary>
        /// 废弃老师课表详情DTO
        /// </summary>
        public AbandoningTeacherScheduleDetailsDto? AbandoningTeacherScheduleDetails { get; set; }

    }

    public class CreateScheduleDto
    {
        /// <summary>
        /// 学生ID
        /// </summary>
        [Required(ErrorMessage = "学生ID不能为空")]
        public Guid StudentId { get; set; }

        /// <summary>
        /// 学生上课类型
        /// </summary>    
        [Required(ErrorMessage = "学生上课类型不能为空")]
        public CourseType CourseType { get; set; }

        /// <summary>
        /// 订单ID
        /// </summary>
        [Required(ErrorMessage = "订单ID不能为空")]
        public Guid? OrderId { get; set; }

    }

    public class CreateTeacherScheduleDetailsDto
    {
        /// <summary>
        /// 教师课表ID
        /// </summary>
        [Required(ErrorMessage = "教师课表ID不能为空")]
        public Guid TeacherScheduleId { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        [Required(ErrorMessage = "开始时间不能为空")]
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        [Required(ErrorMessage = "结束时间不能为空")]
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }
    }

    /// <summary>
    /// 废弃老师课表详情DTO
    /// </summary>
    public class AbandoningTeacherScheduleDetailsDto
    {
        /// <summary>
        /// 教师课表详情ID
        /// </summary>
        [Required(ErrorMessage = "教师课表详情ID不能为空")]
        public Guid TeacherScheduleDetailsId { get; set; }
        /// <summary>
        /// 废弃原因
        /// </summary>
        [Required(ErrorMessage = "废弃原因不能为空")]
        public string Reason { get; set; }
    }


    /// <summary>
    /// 更新教师课表DTO
    /// </summary>
    public class UpdateTeacherScheduleDto
    {
        /// <summary>
        /// 课表ID
        /// </summary>
        [Required(ErrorMessage = "课表ID不能为空")]
        public Guid Id { get; set; }

        /// <summary>
        /// 教室ID
        /// </summary>
        public Guid? ClassroomId { get; set; }

        /// <summary>
        /// 单价(元/课时)
        /// </summary>
        [Range(0, 10000, ErrorMessage = "单价必须在0-10000之间")]
        public decimal? UnitPrice { get; set; }

        /// <summary>
        /// 人数限制
        /// </summary>
        [Range(1, 100, ErrorMessage = "人数限制必须在1-100之间")]
        public int? Capacity { get; set; }

        /// <summary>
        /// 课程Id
        /// </summary>
        public Guid? CourseId { get; set; }

        /// <summary>
        /// 老师id
        /// </summary>
        public Guid? TeacherId { get; set; }

        ///// <summary>
        ///// 上课时间
        ///// </summary>
        //public DateTime? StartTime { get; set; }

        ///// <summary>
        ///// 下课时间
        ///// </summary>
        //public DateTime? EndTime { get; set; }

        /// <summary>
        /// 课表状态
        /// </summary>
        public ScheduleStatus? Status { get; set; }

        /// <summary>
        /// 废弃原因
        /// </summary>
        public string? Reason { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }
    }

    public class UpdateTeacherScheduleDetailsDto
    {
        /// <summary>
        /// 课表详情ID
        /// </summary>
        [Required(ErrorMessage = "课表详情ID不能为空")]
        public Guid Id { get; set; }

        /// <summary>
        /// 课表状态
        /// </summary>
        public ScheduleStatus? Status { get; set; }

        /// <summary>
        /// 老师上课类型
        /// </summary>
        public CourseType? CourseType { get; set; }

        /// <summary>
        /// 废弃原因
        /// </summary>
        public string? Reason { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string? Remarks { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime? StartTime { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>  
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime? EndTime { get; set; }
    }
    /// <summary>
    /// 教师课表集合DTO
    /// </summary>
    public class TeacherScheduleListDto
    {
        /// <summary>
        /// 上课时间
        /// </summary>
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 下课时间
        /// </summary>
        public DateTime EndTime { get; set; }

        /// <summary>
        /// 课程对象
        /// </summary>
        public CourseDto Course { get; set; }

        /// <summary>
        /// 教室对象
        /// </summary>
        public ClassroomDto Classroom { get; set; }

        /// <summary>
        /// 学生集合
        /// </summary>
        public List<StudentDto> Students { get; set; }

        public virtual List<StudentScheduleDetailsDto> StudentScheduleDetails { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public ScheduleStatus Status { get; set; }

        /// <summary>
        /// 老师上课方式类型
        /// </summary>
        public CourseType CourseType { get; set; }

        /// <summary>
        /// 废弃原因
        /// </summary>
        public string Reason { get; set; }



        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }
    }

    public class TeacherScheduleListRequest
    {
        /// <summary>
        /// 教师ID
        /// </summary>
        [Required(ErrorMessage = "教师ID不能为空")]
        
        public Guid TeacherId { get; set; }

        /// <summary>
        /// 开始日期
        /// </summary>
        [Required(ErrorMessage = "开始日期不能为空")]
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime StartDate { get; set; }

        /// <summary>
        /// 结束日期
        /// </summary>
        [Required(ErrorMessage = "结束日期不能为空")]
        [JsonConverter(typeof(CustomDateTimeConverter))]
        public DateTime EndDate { get; set; }
    }

    



}
